#include <iostream>
#include "LinkedList.h"

using namespace std;

// 99.96 %
class Solution
{
public:
  ListNode *deleteDuplicates(ListNode *head)
  {
    if (head == NULL)
    {
      return head;
    }
    ListNode *curNode = head;
    ListNode *delNode = head->next;
    while (delNode != NULL)
    {
      if (delNode->val == curNode->val)
      {
        curNode->next = delNode->next;
        delete delNode;
        delNode = curNode->next;
      }
      else
      {
        curNode = delNode;
        delNode = delNode->next;
      }
    }
    return head;
  }
};

int main()
{
  int arr[] = {};
  int n = sizeof(arr) / sizeof(arr[0]);
  ListNode *list = createLinkedList(arr, n);
  printLinkedList(list);
  list = Solution().deleteDuplicates(list);
  printLinkedList(list);
  deleteLinkedList(list);
  return 0;
}
